package com.xiaoze.stream.service.impl;

import com.xiaoze.stream.entity.Type;
import com.xiaoze.stream.sink.SinkProvider;
import com.xiaoze.stream.service.Sender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@EnableBinding(SinkProvider.class)
public class SenderImpl implements Sender {

    @Autowired
    SinkProvider sinkProvider;

    @Override
    public void sayHello() {
        String message= "小泽发送信息了，现在的时间是：" + new Date();
        sinkProvider.output().send(MessageBuilder.withPayload(message).build());
    }

    @Override
    public void sayHelloAndResponse() {

        Type type = new Type(1 , "衣服");

        sinkProvider.outputSecond().send(MessageBuilder.withPayload(type).build());
    }

}